package com.sm.service;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sm.model.Activities;
import com.sm.model.UserActivities;
import com.sm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sm.dao.ActivitiesMapper;

import java.util.List;

@Service
public class ActivitiesService {

	@Autowired
	private ActivitiesMapper activitiesMapper;
	
	/*public List<Activities> selectActivitiesNow(){

		return activitiesMapper.selectActivitiesNow();
	}
*/
	public Activities selectActivitiesById(Integer activitiesId){
		return activitiesMapper.selectActivitiesById(activitiesId);
	}

	//查询近期活动列表（开始时间倒叙）
	public PageResult getList(Integer currentPage,Integer pageSize){
		PageHelper.startPage(currentPage,pageSize);
		Page<Activities> list = activitiesMapper.getList();
		return new PageResult(list.getTotal(),list);
	}

/*
	public List<Activities> selectActivitiesBefore(){

		return activitiesMapper.selectActivitiesBefore();
	}*/
	
	/**
	 *	根据用户输入的搜索内容作为活动标题查询活动。
	 * @param title		用户的输入的搜索内容作为的活动的标题
	 * @return
	 */
	public PageResult searchActivities(String title,Integer currentPage,Integer pageSize){
		PageHelper.startPage(currentPage,pageSize);
        Page<Activities> activities = activitiesMapper.searchActivities(title);
        return new PageResult(activities.getTotal(),activities);
    }

    public Activities selectByPrimaryKey(Integer id){
		return activitiesMapper.selectByPrimaryKey(id);
	}
}
